/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 有点呆
 * Date: 2024-03-24
 * Time: 16:56
 */

import java.util.Arrays;

public class homework {
    public static void main(String[] args) {

    }
    public static void fun1(int[] array){

    }

    //使数组中的奇数在偶数之前
    public static void main2(String[] args) {

        int[] array = {1, 2, 3, 4, 5, 6};
        trans(array);
        String ret = Arrays.toString(array);
        System.out.println(ret);
    }
    public static void trans(int[] array1){
        int left = 0;
        int right = array1.length-1;//最后一个
        while(left < right){
            //防止越界
            while(left < right && array1[left] % 2 != 0) {
                //奇数
                left++;
            }
            while(left < right && array1[right] % 2 == 0) {
                //偶数
                right--;
            }
            int tmp = array1[left];
            array1[left] = array1[right];
            array1[right] = tmp;
        }
    }

    //将数组中的每个元素*2
    public static void main1(String[] args) {
        int[] array = {1, 2, 3, 4};
        mul(array);
        String ret = Arrays.toString(array);//输出数组类似于用"for"
        System.out.println(ret);
    }
    public static void mul(int[] array1){
        for(int i = 0;i < array1.length;i++){
            array1[i] = array1[i] * 2;
        }
    }
}
